home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / COLISION.TST / SETCOLSN.C < prev   
C/C++ Source or Header  |  1996-02-21  |  5KB  |  163 lines

  1. /* ============ */
  2. /* setcolsn.c    */
  3. /* ============ */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <memory.h>
  7. #include <clsndefs.h>
  8. #include <miscdefs.h>
  9.  
  10. #define ACT(X)    #X
  11.  
  12. #define CLAMP(Out, Var, Lo, Hi) Out = __min(Hi, __max(Lo, Var))
  13.  
  14. #define NEED_ALL(Label) "Enter "Label
  15.  
  16. #define NEED_USER_ENTRY(LABEL, LO, HI) \
  17.     NEED_ALL(LABEL" ["ACT(LO)"-"ACT(HI)"]: ")
  18.  
  19. #define BALLS_LABEL    "Number of Balls"
  20. #define BITS_LABEL    "Number of Bits in Observations"
  21. #define URN_LABEL    "Number of Urns"
  22.  
  23. #define REPORT_USER_INT_ENTRY(Entry, Label)        \
  24.     {                            \
  25.     fflush(NULL);printf("\n");            \
  26.     printf("\tNumber Entered:  %.f", (double)Entry);\
  27.     printf(" (%s)\n", Label);            \
  28.     }
  29. #define SHOW_INT_VALUE_USED(Entered, Used)            \
  30.     printf("\tTest Value Used: %.f%s\n", (double)Used,    \
  31.     ((double)Entered == (double)Used) ? "" : " (Clamped)")
  32.  
  33. static int BitEntries[] = {1, 2, 4, 5, 10};
  34. #define NUM_BIT_ENTRIES (sizeof(BitEntries)/sizeof(BitEntries[0]))
  35.  
  36. static double PctPts[] = { .01, .05, .25, .50, .75, .95, .99, 1.0};
  37. /* ==================================================================== */
  38. /* SetCollisionControls - Puts Run Controls in ClsnData structure    */
  39. /* ==================================================================== */
  40. void
  41. SetCollisionControls(CLSN_DATA_STRU * ClsnData)
  42. {
  43.     UINT    UserUintEntry;
  44.     int     ItsSize, k, MySize;
  45.  
  46.     /* ------------------- */
  47.     /* Get Number of Urns */
  48.     /* ------------------- */
  49. # if 0
  50.     long    UserLongEntry;
  51.     GetLong(NEED_USER_ENTRY(URN_LABEL, MIN_NUM_URNS, MAX_NUM_URNS),
  52.     &UserLongEntry);
  53.  
  54.     REPORT_USER_INT_ENTRY(UserLongEntry, URN_LABEL);
  55.  
  56.     if (UserLongEntry == 0)
  57.     {
  58.     ClsnData->NumCategories = MAX_NUM_URNS;
  59.     }
  60.     else
  61.     {
  62.     CLAMP(ClsnData->NumCategories, UserLongEntry,
  63.         MIN_NUM_URNS, MAX_NUM_URNS);
  64.     }
  65.     SHOW_INT_VALUE_USED(UserLongEntry, ClsnData->NumCategories);
  66. # endif
  67.  
  68.     ClsnData->NumCategories = MAX_NUM_URNS;
  69.  
  70.     /* ------------------- */
  71.     /* Get Number of Balls */
  72.     /* ------------------- */
  73. # if 0
  74.     GetUint(NEED_USER_ENTRY(BALLS_LABEL, MIN_NUM_BALLS, MAX_NUM_BALLS),
  75.     &UserUintEntry);
  76.  
  77.     REPORT_USER_INT_ENTRY(UserUintEntry, BALLS_LABEL);
  78.  
  79.     if (UserUintEntry == 0)
  80.     {
  81.     ClsnData->NumObs = MAX_NUM_BALLS;
  82.     }
  83.     else
  84.     {
  85.     CLAMP(ClsnData->NumObs, UserUintEntry,
  86.         (UINT) MIN_NUM_BALLS, (UINT) MAX_NUM_BALLS);
  87.     }
  88.     SHOW_INT_VALUE_USED(UserUintEntry, ClsnData->NumObs);
  89. # endif
  90.  
  91.     ClsnData->NumObs = MAX_NUM_BALLS;
  92.  
  93.     /* --------------------------------- */
  94.     /* Get Number of Bits in Observation */
  95.     /* --------------------------------- */
  96.     printf("Requesting Number of Random Bits to be Used.\n"
  97.     "Allowed Entries Are:\n");
  98.  
  99.     for (k = 0; k < NUM_BIT_ENTRIES; ++k)
  100.     {
  101.     printf("%4d%s", BitEntries[k],
  102.         (k < NUM_BIT_ENTRIES - 1) ? "," : "\n");
  103.     }
  104.  
  105.     printf("Default is 1 Bit\n");
  106.  
  107.     GetUint(NEED_USER_ENTRY(BITS_LABEL, MIN_NUM_USER_BITS,
  108.         MAX_NUM_USER_BITS), &UserUintEntry);
  109.  
  110.     REPORT_USER_INT_ENTRY(UserUintEntry, BITS_LABEL);
  111.  
  112.     for (k = 0; k < NUM_BIT_ENTRIES; ++k)
  113.     {
  114.     if ((int) UserUintEntry == BitEntries[k])
  115.     {
  116.         break;
  117.     }
  118.     }
  119.  
  120.     if (k == NUM_BIT_ENTRIES)
  121.     {
  122.     ClsnData->NumBits = 1;
  123.     }
  124.     else
  125.     {
  126.     ClsnData->NumBits = (int) UserUintEntry;
  127.     }
  128.  
  129.     SHOW_INT_VALUE_USED(UserUintEntry, ClsnData->NumBits);
  130.  
  131.     /* ---------------------------------- */
  132.     /* Set BitMask Used by GetBitVector() */
  133.     /* ---------------------------------- */
  134.     ClsnData->BitMask = (1 << ClsnData->NumBits) - 1;
  135.     P(printf("ClsnData->BitMask  = %4x\n", ClsnData->BitMask));
  136.  
  137.     /* -------------------------------------------- */
  138.     /* Set Number of Parts That Make Up Data Vector */
  139.     /* -------------------------------------------- */
  140.     ClsnData->NumParts = MAX_NUM_DATA_BITS / ClsnData->NumBits;
  141.     P(printf("ClsnData->NumParts = %4d\n", ClsnData->NumParts));
  142.  
  143.     /* ---------------------------- */
  144.     /* Initialize Percentage Points */
  145.     /* ---------------------------- */
  146.     MySize = sizeof(PctPts);
  147.     ItsSize = sizeof(ClsnData->PctPts);
  148.  
  149.     memcpy(ClsnData->PctPts, PctPts, ItsSize);
  150.     P(printf("SetCollisionControls(): "));
  151.  
  152.     if (MySize == ItsSize)
  153.     {
  154.     P(printf("Percentage Points Initilaized\n"));
  155.     }
  156.     else
  157.     {
  158.     /* Insert &MySize to Silence compiler */
  159.     printf("Initializer for Percentage Points is too %s.\n",
  160.         (MySize < ItsSize) ? "SMALL" : "LARGE", &MySize);
  161.     }
  162. }
  163.